<template>
  <view class="viewport">
    <!-- 考点详情-详细内容 -->
    <swiper class="sign-details" :current="activeIndex" @change="swiperChange">
      <swiper-item v-for="(signItem, signIndex) in signList" :key="signIndex">
        <view class="sign-details-item">
          <view class="sign-icon">
            <image class="img" :src="signItem.imgUrl" mode="heightFix" />
          </view>
          <view class="sign-title">
            {{ signItem.name }}
          </view>
          <view class="sign-intro">
            <scroll-view class="" scroll-y>
              <uv-parse :content="signItem.intro" :tagStyle="{ img: 'width: 50vw;margin-left:25vw;' }"
                :show-img-menu="false"></uv-parse>
            </scroll-view>
          </view>

          <view class="sign-button" v-if="useSignQuestions(baseType!, signItem.parentId!, signItem.id!)!.length > 1"
            @tap="toExercise(signItem.parentId!, signItem.id!)">
            相关试题({{ useSignQuestions(baseType!, signItem.parentId!, signItem.id!)?.length }}题)
          </view>
        </view>

      </swiper-item>
    </swiper>
  </view>

</template>

<script lang="ts" setup>
  import { onLoad, onShow } from '@dcloudio/uni-app'
  import { ref, watch, nextTick } from 'vue'
  import type { SignVo } from '@/api/base/types';
  import { ExerciseTypeEnum } from '@/api/constants'

  import { useSignsStore } from '@/stores/modules/signs_store'
  import { useSignQuestions } from '@/composables/Exercise'

  const signsStore = useSignsStore()
  // 题库类型
  const baseType = ref<string>()
  // 标志父级ID
  const signParentId = ref<number>()
  // 标志列表
  const signList = ref<SignVo[]>([])

  // 当前所有
  const activeIndex = ref<number>(0)

  onLoad((options: any) => {
    baseType.value = options.baseType
    signParentId.value = options.signParentId
    let signsParent = signsStore.signs?.find(item => item.id == signParentId.value)
    let pageTitle = signsParent?.name
    uni.setNavigationBarTitle({
      title: pageTitle!,
    })
    signList.value = signsParent?.children!
    activeIndex.value = Number.parseInt(options.signIndex)
  })

  onShow(() => {
  })


  watch(activeIndex, () => {
    nextTick(() => {
      let pageTitle = activeIndex.value + 1 + '/' + signList.value.length
      uni.setNavigationBarTitle({
        title: pageTitle!,
      })
    })
  }, {
    immediate: true,
  })
  // swiperChange
  const swiperChange = (e: UniHelper.SwiperOnChangeEvent) => {
    activeIndex.value = e.detail.current

  }

  // 去练习
  const toExercise = (signParentId: number, signId: number) => {
    uni.navigateTo({
      url: `/pagesExercise/answer/answer?exerciseType=${ExerciseTypeEnum.SignQuestionExercise}&baseType=${baseType.value}&signParentId=${signParentId}&signId=${signId}`
    })
  }
</script>

<style lang="scss" scoped>
  page {
    background-color: #fff;
  }

  .viewport {
    display: flex;
    flex-direction: column;
    background-color: #fff;
  }

  .sign-details {
    display: flex;
    flex-direction: column;

    .sign-details-item {
      display: flex;
      flex-direction: column;
      align-items: center;
      margin: 70rpx 70rpx;
      padding: 80rpx;
      height: 1132rpx;
      box-shadow: 4rpx 3rpx 40rpx 0rpx rgba(113, 113, 113, 0.07),
        4rpx 3rpx 40rpx 0rpx rgba(113, 113, 113, 0.07);
      border-radius: 10rpx;

      .sign-icon {
        display: flex;
        justify-content: center;

        .img {
          height: 400rpx;
        }
      }

      .sign-title {
        margin-top: 40rpx;
        font-size: 40rpx;
        color: #222222;
        font-weight: bold;
        text-align: center;
      }

      .sign-intro {
        margin-top: 40rpx;
        height: 120px;
        font-size: 32rpx;
        color: #4d4d4d;
        line-height: 1.5;
      }

      .sign-button {
        display: flex;
        justify-content: center;
        align-items: center;
        margin-top: 60rpx;
        width: 287rpx;
        height: 88rpx;
        font-size: 30rpx;
        color: #323232;
        border-radius: 44rpx;
        border: solid 2rpx #d3d3d3;
      }
    }


  }

</style>
